﻿Imports Telerik.Web.UI

Partial Class RecieptVoucher
    Inherits System.Web.UI.Page

    Dim _CommandName As String
    Public strConnection As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ConnectionString.ToString

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim _lblPageTitle As Label
            _lblPageTitle = Me.Master.FindControl("lblPageTitle")
            _lblPageTitle.Text = GetLocalResourceObject("PageTitle")
        End If
    End Sub

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Me.Theme = GetGlobalResourceObject("SystemResource", "Theme")
    End Sub

    Protected Sub rgReceiptVoucher_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles rgReceiptVoucher.ItemCommand
        _CommandName = e.CommandName

        If _CommandName = "InitInsert" Then
            '"Add new" button clicked
            Dim editColumn As GridEditCommandColumn = DirectCast(rgReceiptVoucher.MasterTableView.GetColumn("EditCommandColumn"), GridEditCommandColumn)
            'editColumn.Visible = False
            e.Canceled = True

            'Set the default value for the checkbox
            Dim newValues As New System.Collections.Specialized.ListDictionary()
            newValues("IsCash") = False

            'Set the default value for the drop down list

            'newValues["yourDropDownList"] = "Active";

            e.Item.OwnerTableView.InsertItem(newValues)

        End If

    End Sub

    Protected Sub rgReceiptVoucher_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles rgReceiptVoucher.ItemDataBound

        If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) And _CommandName <> "InitInsert" Then
            'If (TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode) Then

            Dim editFormItem As GridEditFormItem = CType(e.Item, GridEditFormItem)
            Dim parentItem As GridDataItem = editFormItem.ParentItem

            Dim box As RadComboBox = CType(editFormItem.FindControl("rcbReceiptFrom").FindControl("rcbd"), RadComboBox)
            If Not (parentItem("ReceiptFrom_ID").Text = "&nbsp;") And box IsNot Nothing Then
                box.SelectedValue = parentItem("ReceiptFrom_ID").Text
            End If
            'Dim box1 As RadComboBox = CType(editFormItem.FindControl("WUCBank").FindControl("rcbd"), RadComboBox)
            'box1.SelectedValue = parentItem("BankAccountNo").Text

        End If

    End Sub

End Class
